// pages/module/promote/promote.js
import {
   search,
  vity,
  item_select,
 // item_select
} from '../../../../utils/imapi.js';
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    items:[],
    img:'',
    background:'#FFE1E1',
    top:'活动页',
    is_load: false,
    page_index: 1,
    tabData:'',
    cur_scroll_top:0,
    code:'',
    extras:[],
	page_size:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad:async function (options) {
	  console.log(options);

	 this.setData({
		 code:options.choice_code
	 })
	 if(options.choice_code!=''&&options.type==0){
      this.loadData(1)
		  
	 }else{
		 
    const vv=await vity({view_code:options.view_code});
	
    this.setData({
         img:vv.data.banner_img,
         background:vv.data.bg_color,
         top:vv.data.url_type_name,
         code:vv.data.biz_code,
		 extras:JSON.parse(vv.data.extras),
    })
	 console.log(this.data.extras);
	 
    this.loadData(1)
   
	 }
	
	  
    
  },

  loadData:async function(page_index){

    this.setData({

      is_load: true,
    })
    const Hot=await item_select({biz_code:this.data.code,page_index: page_index, page_size:this.data.extras.page_size});
    
    this.setData({
      is_load: false,
    })

    if(Hot.code==0){
      this.setData({
        items:this.data.items.concat(Hot.data),
        page_index:page_index
      })
    }
    
    console.log(this.data.items);

    
  },


  onPageScroll: function (e) {
    var that = this;
    console.log(e.scrollTop);
      that.setData({
        cur_scroll_top: e.scrollTop
      })
  
  },
  // ducat(e){
	 //  console.log(e);
	 //  var p=e.currentTarget.dataset.id.p;
	 //  var id=e.currentTarget.dataset.id.item_id;
	 //  var index = e.currentTarget.dataset.index;
	 //  app.globalData.cur_product = this.data.hot_items[index];
	 //  wx.navigateTo({
	 //      url: '/pages/module/productDetail/productDetail?id=' + id + '&p=' + p,
	 //  })
  // },
  onReachBottom: async function () {
    if ( this.data.is_load || !this.data.extras.pager_enable) return;
    this.loadData(this.data.page_index++)
	
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})